Audio Output Method, Electronic Device, and Storage Medium

ABSTRACT

An audio output method applied to an electronic device having a proximity sensor, where the method includes obtaining proximity data of the proximity sensor when the electronic device is coupled to an audio output device and has an audio signal to output, outputting, by an earpiece of the electronic device, the audio signal when the proximity data meets a preset condition, determining a type of the audio output device, and selecting, based on the type of the audio output device, whether to output the audio signal using the audio output device. Hence, an earpiece is enabled to output an audio signal under a specific condition when an electronic device including a mobile phone is coupled to another audio output device, thereby improving user experience.

TECHNICAL FIELD

Embodiments of the present invention relate to the terminal field, andin particular, to an audio output method, an electronic device, and astorage medium.

BACKGROUND

Currently, in addition to a built-in earpiece, a mobile phone may alsobe connected to another audio output device such as a wired earphone, aBluetooth earphone, and a loudspeaker stereo.

In the prior art, when a mobile phone receives user-entered indicationinformation indicating that a new incoming call has been answered, themobile phone first determines whether the mobile phone is currentlyconnected to another audio output device different from an earpiece. Ifthe mobile phone is connected to the another audio output device, theaudio output device outputs a call voice signal; or if the mobile phoneis not connected to the another audio output device, the earpiece of themobile phone outputs a call voice signal.

It can be learned from the above that in the prior art, if it isdetermined that the mobile phone is connected to the another audiooutput device, the audio output device outputs the call voice signal,and the earpiece of the mobile phone does not output the call voicesignal. When answering the call by using the earpiece of the mobilephone, a user hears no sound. In this case, the user may mistakenlyconsider that the call is abnormal, and hang up. Alternatively, a userfirst realizes that a wrong answering device is used to answer the call,and can hear a call sound normally only after changing the answeringdevice, delivering undesired user experience.

SUMMARY

Embodiments of the present invention provide an audio output method, anelectronic device, and a storage medium, to improve user experience whenan electronic device including a mobile phone is connected to anotheraudio output device.

According to a first aspect, an audio output method is provided, wherethe method is applied to an electronic device having a proximity sensor,and the method includes: obtaining proximity data of the proximitysensor when the electronic device is connected to an audio output deviceand has a to-be-output audio signal; outputting, by an earpiece of theelectronic device, the audio signal when the proximity data meets apreset condition, and determining a type of the audio output device; anddetermining, based on the type of the audio output device, whether theaudio output device outputs the audio signal.

It can be learned from the above that in this embodiment of the presentinvention, it can be determined, based on that the proximity data meetsthe preset condition, that a user places the electronic device (forexample, a mobile phone) near an ear for answering, so that the user canalso hear a sound from the earpiece when placing the electronic devicenear the ear for answering. In this way, user experience is improvedwhen the electronic device is connected to another audio output device.In addition, there are two audio signal output ways based on the type ofaudio output device: Both the earpiece and the audio output deviceoutput the audio signal, and only the earpiece outputs the audio signal.Based on the type of audio output device, one of the two ways isselected to output the audio signal. This improves flexibility ofoutputting the audio signal.

In a possible implementation, the method further includes: outputting,by the electronic device, prompt information when the earpiece of theelectronic device outputs the audio signal, where the prompt informationis a text prompt or a sound prompt.

It can be learned from the above that in this embodiment of the presentinvention, after the electronic device is connected to the audio outputdevice, the audio signal is usually output by only the audio outputdevice instead of the earpiece, and therefore when the earpiece of theelectronic device outputs the audio signal, the electronic deviceoutputs the prompt information. This can improve user experience.

In a possible implementation, the determining, based on the type of theaudio output device, whether the audio output device outputs the audiosignal includes: outputting, by the audio output device, the audiosignal when the audio output device is an earphone.

It can be learned from the above that in this embodiment of the presentinvention, when the type of the audio output device indicates that theaudio output device is the earphone, that is, when the audio outputdevice has no loudspeaking function, the audio signal is output by theearpiece and the earphone. In this way, when user behavior isinaccurately identified based on that the proximity data meets thepreset condition, the user can still hear a sound from the earphone.

In a possible implementation, the determining, based on the type of theaudio output device, whether the audio output device outputs the audiosignal includes: skipping, by the audio output device, outputting theaudio signal when the audio output device is a loudspeaking device.

It can be learned from the above that in this embodiment of the presentinvention, when the type of the audio output device indicates that theaudio output device has a loudspeaking function, the audio signal isoutput by using only the earpiece. This can protect user privacy andprevent another person from hearing the audio signal.

In a possible implementation, the proximity data is a distance betweenthe electronic device and an obstacle, and that the proximity data meetsa preset condition includes: the distance between the electronic deviceand the obstacle is less than or equal to a preset distance.

It can be learned from the above that in this embodiment of the presentinvention, a manner of identifying user behavior is simple, easy toimplement, and quick to determine, and is particularly suitable for aspecific scenario in which the user places the mobile phone near the earfor answering.

In a possible implementation, duration in which the proximity data meetsthe preset condition is greater than a preset time length.

It can be learned from the above that in this embodiment of the presentinvention, that the proximity data meets the preset condition isdetermined by determining that the duration in which the proximity datameets the preset condition is greater than the preset time length. Thisimproves accuracy of determining that the proximity data meets thepreset condition. In a possible implementation, the proximity datarepresents a distance between the electronic device and an obstacle; theobtaining proximity data of the proximity sensor when the electronicdevice is connected to an audio output device and has a to-be-outputaudio signal includes: when the electronic device is connected to theaudio output device and has the to-be-output audio signal, obtaining aplurality of pieces of proximity data of the proximity sensor within apreset time length; and that the proximity data meets a preset conditionis specifically: At least one of the plurality of pieces of proximitydata meets a first preset condition, and/or a time-based change trend ofthe plurality of pieces of proximity data meets a second presetcondition.

That at least one of the plurality of pieces of proximity data meets afirst preset condition may be specifically: At least one of theplurality of pieces of proximity data is less than or equal to a presetdistance. That a time-based change trend of the plurality of pieces ofproximity data meets a second preset condition may be specifically: Thetime-based change trend of the plurality of pieces of proximity data isa decreasing trend.

It can be learned from the above that in this embodiment of the presentinvention, whether the proximity data meets the preset condition isdetermined by obtaining the plurality of pieces of proximity data withinthe preset time length and considering the change trend of the pluralityof pieces of proximity data, so as to determine user behavior. Thismanner can improve accuracy of a determining result.

In a possible implementation, the outputting, by an earpiece of theelectronic device, the audio signal when the proximity data meets apreset condition includes: setting an audio type of the audio signal toa custom audio type when the proximity data meets the preset condition:and outputting, by the earpiece, the audio signal based on a presetcorrespondence between the custom audio type and the earpiece.

It can be learned from the above that for a common case in audio signaloutput after the electronic device is connected to the audio outputdevice, to be specific, the audio signal is usually output by only theaudio output device instead of the earpiece, in this embodiment of thepresent invention, the custom audio type is used and the correspondencebetween the custom audio type and the earpiece is preset, so that afterthe electronic device is connected to the audio output device, theearpiece of the electronic device outputs the audio signal when theproximity data meets the preset condition. This implementation isrelatively clever and easy to implement.

According to another aspect, an electronic device is provided. Theelectronic device includes a processor, a memory, an earpiece, aproximity sensor, and an interface circuit. The memory is configured tostore computer executable program code, the program code includes aninstruction, and when the processor executes the instruction, the methodof the first aspect is implemented. For an implementation and abeneficial effect of resolving a problem by the electronic device, referto the first aspect, the possible implementations of the first aspect,and the beneficial effect thereof. Details are not described hereinagain.

According to still another aspect, an embodiment of the presentinvention provides an electronic device. The electronic device includesan obtaining unit and a processing unit; the obtaining unit isconfigured to obtain proximity data of a proximity sensor when theelectronic device is connected to an audio output device and has ato-be-output audio signal; and the processing unit is configured to:determine that an earpiece of the electronic device outputs the audiosignal when the proximity data obtained by the obtaining unit meets apreset condition, and determine a type of the audio output device, anddetermine, based on the type of the audio output device, whether theaudio output device outputs the audio signal. Based on a same inventionidea, for a principle and a beneficial effect of resolving a problem bythe electronic device, refer to the first aspect, the possibleimplementations of the first aspect, and the beneficial effect thereof.Therefore, for implementation of the electronic device, refer to theimplementation of the method. Details are not described herein again.

According to yet another aspect, an embodiment of the present inventionprovides a computer storage medium configured to store a computersoftware instruction used in a designed solution of the method of thefirst aspect.

Compared with the prior art, in the embodiments of the presentinvention, it can be determined, based on that the proximity data meetsthe preset condition, that the user places the electronic device nearthe ear for answering, so that the user can also hear a sound from theearpiece when placing the electronic device near the ear for answering.In this way, user experience is improved when the electronic device isconnected to another audio output device. In addition, there are twoaudio signal output ways based on the type of audio output device: Boththe earpiece and the audio output device output the audio signal, andonly the earpiece outputs the audio signal. Based on the type of audiooutput device, one of the two ways is selected to output the audiosignal. This improves flexibility of outputting the audio signal by theelectronic device.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a flowchart of an audio output method according to anembodiment of the present invention;

FIG. 2 is a flowchart of another audio output method according to anembodiment of the present invention:

FIG. 3 is a schematic diagram of an audio output structure of a mobilephone operating system;

FIG. 4 is a structural diagram of an electronic device according to anembodiment of the present invention; and

FIG. 5 is a structural diagram of another electronic device according toan embodiment of the present invention.

DESCRIPTION OF EMBODIMENTS

To make the objectives, technical solutions, and advantages of theembodiments of the present invention clearer, the following describesthe technical solutions in the embodiments of the present invention withreference to the accompanying drawings in the embodiments of the presentinvention. Apparently, the described embodiments are some rather thanall of the embodiments of the present invention. All other embodimentsobtained by a person of ordinary skill in the art based on theembodiments of the present invention without creative efforts shall fallwithin the protection scope of the present invention.

FIG. 1 is a flowchart of an audio output method according to anembodiment of the present invention. The method may be performed by anelectronic device having a proximity sensor, for example, a mobilephone. The method includes:

obtaining proximity data of the proximity sensor when the electronicdevice is connected to an audio output device and has a to-be-outputaudio signal; outputting, by an earpiece of the electronic device, theaudio signal when the proximity data meets a preset condition, anddetermining a type of the audio output device; and determining, based onthe type of the audio output device, whether the audio output deviceoutputs the audio signal.

It should be understood that in this embodiment of the presentinvention, the electronic device may be referred to as a terminal, userequipment (User Equipment, “UE” for short), a mobile station (MobileStation, “MS” for short), a mobile terminal (Mobile Terminal), acomputer, a microcomputer, or the like. The electronic device maycommunicate with one or more core networks by using a radio accessnetwork (Radio Access Network, “RAN” for short). For example, theelectronic device may be a mobile phone (or referred to as a “cellular”phone), a computer having a mobile terminal, or the like. For example,the electronic device may alternatively be a portable, pocket-sized,handheld, computer built-in, or in-vehicle mobile apparatus thatexchanges voice and/or data with a radio access network. This is notlimited in the present invention. For example, the electronic devicealternatively includes a wired electronic device having a multi-carrierfeature.

The following details an implementation solution of the method steps.

Step 101: Obtain proximity data of the proximity sensor when theelectronic device is connected to an audio output device and has ato-be-output audio signal.

The audio output device may be a device that can output the audiosignal, for example, an earphone or a stereo, and is different from theearpiece. The audio output device may be connected to the electronicdevice in a wired or wireless manner. The audio output device may be aBluetooth device, a Wireless Fidelity (Wireless-Fidelity, wifi) device,or a device connected by using another connection interface.

The output audio signal may be triggered by an audio output event, andthe audio output event may be an audio output event such as an incomingcall voice, a ringtone, a Voice over Internet Protocol (Voice overInternet Protocol, voip) voice, text to speech (Text to Speech, TTS)broadcast, or music play.

The electronic device analyzes the proximity data to determine userbehavior, for example, determining that a user places the electronicdevice near an ear, and modifies at least one setting of the electronicdevice in response to an analysis result, for example, how to processinput or output data from an input/output device. The electronic devicemay be a telephone such as a cellular telephone, or an integratedtelephone and media player, or another type of device that may include asensor and process data from the sensor. In addition, the input/outputdevice may be an audio input/output device, a keypad, or a multi-touchinput pad. The sensor may be any one of various sensors including aproximity sensor, a temperature sensor, an accelerometer, a lightsensor, a position determining device, an orientation determiningdevice, a radio frequency electromagnetic wave sensor, a touch inputpad, a motion sensor, or a sound sensor. In some embodiments, theelectronic device may include a plurality of sensors that provide datato at least one processor together, and the processor analyzes the datato determine user behavior. In at least some embodiments, artificialintelligence processing may be used during analysis, and the processingincludes comparing data obtained from one or more sensors with athreshold, for example, comparing data from the proximity sensor withthe threshold. The threshold represents a distance between a part of thedevice and an ear or a head of the user. The data from the sensor mayrepresent a simulated value detected by the sensor. The simulated valuemay indicate any one of various simulated values including, for example,a distance, a temperature, light intensity, a measurement of motion ororientation, a sound intensity measurement, or a radio frequency (RadioFrequency, RF) electromagnetic measurement. In at least someembodiments, artificial intelligence may be needed to process receiveddata and select an interpretation of the data from a set of possibleinterpretations, and the selected interpretation is further used todetermine how to modify the at least one setting. The modified settingmay be any one of various settings including, for example, a setting ofan illuminator of a display, a setting of a sound input or outputparameter, a setting of a sound output device, a setting of a status ofan input device related to user input reception, a setting of acommunications parameter, a setting of a processor, or a setting of adevice mode (for example, a cellular phone mode or a media player mode).

Step 102: When the proximity data meets a preset condition, an earpieceof the electronic device outputs the audio signal.

In an example, the proximity data may represent a distance between theelectronic device and an obstacle.

When the proximity data meets the preset condition, that is, thedistance between the electronic device and the obstacle is less than orequal to a preset distance, the earpiece of the electronic deviceoutputs the audio signal.

In an example, when the earpiece of the electronic device outputs theaudio signal, the electronic device outputs prompt information, and theprompt information is a text prompt or a sound prompt used to notify theuser that the earpiece has output the audio signal.

In an example, when the proximity data does not meet the presetcondition, that is, when the distance between the electronic device andthe obstacle is greater than the preset distance, the audio signal isoutput by the audio output device instead of the earpiece of theelectronic device.

In an example, the proximity data represents a distance between theelectronic device and an obstacle. In step 101, when the electronicdevice is connected to an audio output device and has a to-be-outputaudio signal, a plurality of pieces of proximity data of the proximitysensor are obtained within a preset time. In step 102, that theproximity data meets a preset condition is specifically: At least one ofthe plurality of pieces of proximity data meets a first presetcondition, and/or a time-based change trend of the plurality of piecesof proximity data meets a second preset condition, and duration in whichthe proximity data meets the preset condition is greater than a presettime.

The proximity data represents the distance between the electronic deviceand the obstacle, and that at least one of the plurality of pieces ofproximity data meets a first preset condition means that the distancebetween the electronic device and the obstacles is less than or equal toa preset distance. That a time-based change trend of the plurality ofpieces of proximity data meets a second preset condition may bespecifically: The time-based change trend of the plurality of pieces ofproximity data is a decreasing trend.

It can be learned from the above that in this embodiment of the presentinvention, that the proximity data meets the preset condition isdetermined by determining that the duration in which the proximity datameets the preset condition is greater than the preset time. Thisimproves accuracy of determining that the proximity data meets thepreset condition.

Step 103: Determine a type of the audio output device.

Specifically, the audio output device can be classified into twocategories. One category is an audio output device having a loudspeakingfunction that is a loudspeaking device for short, for example, aloudspeaker stereo. The other category is an audio output device havingno loudspeaking function, for example, an earphone.

In this embodiment of the present invention, no specific limitation isimposed on an execution order of step 102 and step 103. Step 102 may beperformed before step 103, or step 103 may be performed before step 102,or step 102 and step 103 may be performed simultaneously.

Step 104: Determine, based on the type of the audio output device,whether the audio output device outputs the audio signal.

In an example, when the audio output device is an earphone, the audiooutput device outputs the audio signal.

In an example, when the audio output device is a loudspeaking device,the audio output device skips outputting the audio signal.

In this embodiment of the present invention, when the earpiece of theelectronic device outputs the audio signal, the audio output device mayor may not output the audio signal. In an example, it may be determined,based on the type of the audio output device, whether the audio outputdevice outputs the audio signal. When the type of the audio outputdevice indicates that the audio output device does not have aloudspeaking function (such as an earphone), the audio output deviceoutputs the audio signal. This can prevent the user from hearing, when awrong result is determined, no sound by using the audio output device.When the type of the audio output device indicates that the audio outputdevice has a loudspeaking function (such as a stereo), the audio outputdevice skips outputting the audio signal, to protect user privacy.

In an example, the following manner may be used to enable the earpieceof the electronic device to output the audio signal: when the proximitydata meets the preset condition, setting an audio type of the audiosignal to a custom audio type; and outputting, by the earpiece, theaudio signal based on a preset correspondence between the custom audiotype and the earpiece.

In an example, the following manner may be used to enable the earpieceand the audio output device of the electronic device to output the audiosignal: when the proximity data meets the preset condition and the audiooutput device does not have a loudspeaking function, setting an audiotype of the audio signal to a custom audio type: and outputting, by theearpiece and the audio output device, the audio signal based on a presetcorrespondence between the custom audio type and the earpiece and theaudio output device.

In this embodiment of the present invention, it can be determined, basedon that the proximity data meets the preset condition, that the userplaces the electronic device near an ear for answering, so that the usercan also hear a sound from the earpiece when placing the electronicdevice near the ear for answering. In this way, user experience isimproved when the electronic device is connected to another audio outputdevice. In addition, there are two audio signal output ways based on thetype of audio output device: Both the earpiece and the audio outputdevice output the audio signal, and only the earpiece outputs the audiosignal. Based on the type of audio output device, one of the two ways isselected to output the audio signal. This improves flexibility ofoutputting the audio signal by the electronic device.

The following specifically describes, by using an example of anapplication scenario in which a user answers a call by using a mobilephone, an audio output method provided in the present invention.

FIG. 2 is a flowchart of another audio output method according to anembodiment of the present invention. The method is performed by a mobilephone having a proximity sensor. The method includes the followingsteps.

Step 201: When receiving user-entered indication information indicatingthat an incoming call has been answered, the mobile phone determinesthat the mobile phone is connected to another audio output devicedifferent from an earpiece, and determines a type of the audio outputdevice.

The mobile phone may detect not only another audio output deviceconnected in a wired manner that is different from the earpiece, butalso another audio output device connected in a wireless manner that isdifferent from the earpiece.

The audio signal includes an incoming call ringtone signal and/or a callvoice signal.

The electronic device dynamically updates an audio policy table based onthe audio signal and the connected another audio output device. Theaudio policy table includes a correspondence between the audio signaland an audio output device that is to output the audio signal.

For example, when there is an incoming call ringtone, the electronicdevice configures, by querying the audio policy table, an audio outputdevice corresponding to the incoming call ringtone.

Step 202: Obtain proximity data of a proximity sensor.

In this embodiment of the present invention, the proximity sensor may bespecifically a distance sensor, and the proximity data may represent adistance between the mobile phone and an obstacle. An implementationmethod of obtaining the proximity data is the same as the implementationmethod of obtaining the proximity data in step 101.

Step 203: When the proximity data meets a preset condition, an earpieceof the mobile phone outputs an audio signal.

In this embodiment of the present invention, whether the earpiece of theelectronic device outputs the audio signal is determined by determiningwhether the proximity data meets the preset condition, to be specific,whether a user places the mobile phone near an ear. When the proximitydata meets the preset condition, to be specific, when the user placesthe mobile phone near the ear, the earpiece of the mobile phone outputsthe audio signal.

In this embodiment of the present invention, whether to output the audiosignal by using the earpiece of the mobile phone is determined bydetecting the distance between the mobile phone and the obstacle. Whenthe proximity data meets the preset condition, to be specific, when thedistance between the mobile phone and the obstacle is less than or equalto an effective answering distance, it is determined that the userplaces the mobile phone near the ear, and the audio signal is output bythe earpiece. When the proximity data does not meet the preset conditionis met, to be specific, when the distance between the mobile phone andthe obstacle is greater than the effective answering distance, it isdetermined that the user does not place the mobile phone near the ear,and the earpiece of the mobile phone skips outputting the audio signal.

That the proximity data meets the preset condition includes: Duration inwhich the proximity data meets the preset condition is greater than apreset time, to be specific, duration in which the user places themobile phone near the ear is greater than the preset time. When theduration in which the user places the mobile phone near the ear isgreater than the preset time, the earpiece of the mobile phone outputsthe audio signal. This improves accuracy of a detection result. Thepreset time is, for example, 2 seconds.

Step 204: Determine, based on the type of the audio output device,whether the audio output device outputs the audio signal.

When the audio output device is an earphone having no loudspeakingfunction, the audio output device outputs the audio signal. When theaudio output device is a device having a loudspeaking function, theaudio output device skips outputting the audio signal.

In this embodiment of the present invention, when the mobile phone isconnected to the another audio output device and receives indicationinformation indicating that an incoming call has been answered, themobile phone detects that the user places the mobile phone near the ear,and the user can hear a sound from the earpiece. In addition, whetherthe audio output device outputs the call voice signal may also bedetermined based on the type of the audio output device.

In an example, when the proximity data meets the preset condition, anaudio type of the audio signal is set to a custom audio type: and anaudio output device corresponding to the custom audio type outputs theaudio signal based on a preset correspondence between the custom audiotype and the earpiece. For example, a correspondence between an audiotype and an audio output device may be shown in Table 1.

TABLE 1 Audio type Audio output device Music Loudspeaker Call ringtoneLoudspeaker Call voice Earphone Custom audio type 1 Earpiece Customaudio type 2 Earpiece + earphone

In this embodiment of the present invention, when the audio outputdevice is an earphone having no loudspeaking function, the audio outputdevice outputs the call voice signal, that is, both the earpiece and theearphone output the call voice signal. In this way, when a determiningresult that the user places the mobile phone near an ear is incorrect,the user can still hear a call voice by using the earphone. Thisimproves user experience. When the audio output device is a devicehaving a loudspeaking function, the audio output device skips outputtingthe call voice signal. In other words, only the earpiece outputs thecall voice signal. This can prevent another person from hearing the callvoice signal and protects user privacy.

In an example, the method further includes the following step:

Step 205: The audio output device outputs the audio signal when theproximity data does not meet the preset condition.

Step 205 may be implemented in a manner of presetting a correspondencebetween the audio type and the audio output device.

The following describes, by using a specific embodiment, a method fordetermining the type of audio output device provided in the presentinvention.

In an example, the following manner may be used to determine whether adevice is inserted into the mobile phone in a wired manner:

using an isWiredHeadsetOn( ) method in AudioManager provided in anAndroid system, where the method returns true if a device is insertedinto the mobile phone in a wired manner; otherwise, the method returnsfalse.

Optionally, after it is determined that a wired device is inserted,whether the inserted device is a wired earphone or a wired stereo isdetermined based on an impedance characteristic.

In an example, the following manner may be used to determine whetherthere is an audio output device such as an earphone or a loudspeakerstereo connected to the mobile phone through Bluetooth:

obtaining a Bluetooth type of a Bluetooth device connected to the mobilephone, and when the Bluetooth type is any one type in anaudio-output-device Bluetooth type list, determining that there is anaudio output device connected to the mobile phone through Bluetooth.

The Android system itself specifies a series of Bluetooth types.Specifically, a BluetoothClass.Device class defines a series ofBluetooth types, including an earphone type, an in-vehicle device type,and the like. The mobile phone determines a Bluetooth type of aconnected Bluetooth device (Bluetooth Device) based on a property of theBluetooth device, and may find a corresponding type by comparing theBluetooth type with the types specified in BluetoothClass.Device. Thefollowing shows types agreed upon by Bluetooth manufacturers:

-   -   int AUDIO_VIDEO_CAMCORDER    -   int AUDIO_VIDEO_CAR_AUDIO    -   int AUDIO_VIDEO_HANDSFREE    -   int AUDIO_VIDEO_HEADPHONES    -   int AUDIO_VIDEO_HIFI_AUDIO    -   int AUDIO_VIDEO_LOUDSPEAKER    -   int AUDIO_VIDEO_MICROPHONE

When BluetoothDevice==

-   -   AUDIO_VIDEO_CAR_AUDIO∥AUDIO_VIDEO_HANDSFREE∥AUDIO_VIDEO_HEADPHONES∥AUDIO_VIDEO_HIFI_AUDIO∥AUDIO_VIDEO_MICROPHONE,

it is determined that the audio output device such as an earphone or aloudspeaker stereo is connected to the mobile phone through Bluetooth.

The following specifically describes, with reference to an audio outputstructure of a mobile phone operating system (Operating System. OS), anaudio output method provided in an embodiment of the present invention.

FIG. 3 is a schematic diagram of an audio output structure of a mobilephone OS. Referring to FIG. 3, audio output sequentially passes throughthree layers: an application layer, a Java framework, and AudiHAL.

Phone app is a phone application program at the application layer. Thephone application program can alert the user to an incoming call,receive an indication message indicating that the user has answered thenew incoming call, and send a notification message to AudioService inthe Java framework when determining that the proximity data meets thepreset condition, to be specific, the mobile phone is close to an ear.The notification message is used to indicate that the mobile phone isplaced near the ear.

AudioService belongs to the Java framework layer and is a base for anaudio system in the Android OS. Main functions of AudioService arevolume control, volume key processing, and audio I/O device management.In this embodiment of the present invention, after receiving thenotification message sent by Phone app, AudioService sends thenotification message to AudioSystem.

AudioSystem belongs to the Java framework layer, acts as an entry pointfor obtaining an audio system resource, and allows querying andaccessing a mixer installed on the system. AudioSystem includes manymethods for changing audio data from one format to another, and methodsfor performing conversion between an audio file and a stream. Afterreceiving the notification message sent by AudioService, AudioSystemsends the notification message to AudioPolicyManager at the AudiHALlayer.

The AudiHAL layer is a bottom audio layer of the Android system and is alogical layer for communication and control within a same audio device.An audio management strategy of the Android system is: The Androidsystem sets different routes for different audio types, selectsdifferent output devices based on the routes, and the audio outputdevice connected to the electronic device creates a correspondence basedon the audio type and the audio output device connected to theelectronic device. For example, when a type of audio sent by theapplication layer to AudioService is STREAM_MUSIC and the electronicdevice is connected to an earphone, it is determined, based on the audiopolicy table, a sound whose audio type is STREAM_MUSIC is output fromthe earphone. If a type of audio is STREAM_RING the audio issimultaneously emitted from both the earphone and the loudspeaker(speaker).

Selecting corresponding output devices for different audio types basedon the routes mainly depends on a getDeviceForStrategy method ofAudioPolicyManager. Therefore, the audio management policy of theAndroid system can be customized by adding a custom audio type andmodifying an audio policy of getDeviceForStrategy.

For example, an audio type STREAM_CALLING_NEW is newly added, and acorresponding audio output device configured for the audio type is asthe earpiece and the earphone of the mobile phone.

When receiving the notification message transferred by an upper-layerapplication, AudioPolicyManager sets the audio type toSTREAM_CALLING_NEW, and in getDeviceForStrategy method, the earpiece andthe earphone of the mobile phone are selected as output devices based ona modified audio policy.

The audio output method provided in this embodiment of the presentinvention is simple and easy to implement, and improves user experience.

FIG. 4 is a structural diagram of an electronic device according to anembodiment of the present invention. The electronic device is configuredto perform the audio output method provided in the embodiments of thepresent invention. The electronic device includes:

a processor 401, a memory 402, an earpiece 403, a proximity sensor 404,and an interface circuit 405.

The memory 402 is configured to store computer executable program code,and the program code includes an instruction.

The processor 401 invokes the instruction stored in the memory 402 toimplement step 101 to step 104 in FIG. 1, step 201 to step 205 in FIG.2, and the solution designed in the audio output method. For animplementation and a beneficial effect of resolving a problem by theelectronic device, refer to the implementation and the beneficial effectof the foregoing method. Therefore, for implementation of the electronicdevice, refer to the implementation of the method. Details are notdescribed herein again.

FIG. 5 is a structural diagram of another electronic device according toan embodiment of the present invention. The electronic device isconfigured to perform the audio output method provided in theembodiments of the present invention. The electronic device includes anobtaining unit 501 and a processing unit 502. The obtaining unit 501 isconfigured to implement step 101 in FIG. 1 and step 202 in FIG. 2. Theprocessing unit 502 is configured to perform step 102 to step 104 inFIG. 1, step 201, and step 203 to step 205 in FIG. 2, and the audiooutput method. For an implementation and a beneficial effect ofresolving a problem by the electronic device, refer to theimplementation and the beneficial effect of the foregoing method.Therefore, for implementation of the electronic device, refer to theimplementation of the method. Details are not described herein again.

A person skilled in the art may be further aware that the units andalgorithm steps in the examples described in the embodiments disclosedin this specification may be implemented by electronic hardware,computer software, or a combination thereof. To clearly describe theinterchangeability between the hardware and the software, the foregoinghas generally described compositions and steps of each example based onfunctions. Whether the functions are performed by hardware or softwaredepends on particular applications and design constraints of thetechnical solutions. A person skilled in the art may use a differentmethod to implement the described functions for each particularapplication, but it should not be considered that the implementationgoes beyond the scope of the present invention.

In the several embodiments provided in this application, it should beunderstood that the disclosed electronic device and method may beimplemented in other manners. For example, the embodiments describedabove are merely examples. For example, division of the units is merelylogical function division, and may be other division in actualimplementation. For example, a plurality of units or components may becombined or may be integrated into another apparatus, or some featuresmay be ignored or may not be performed. In addition, the displayed ordiscussed mutual couplings or direct couplings or communicationconnections may be implemented through some interfaces. The indirectcouplings or communication connections between electronic devices orunits may be implemented in electrical, mechanical, or other forms.

The units described as separate parts may or may not be physicallyseparate. Parts displayed as units may or may not be physical units, maybe located in one position, or may be distributed on a plurality ofnetwork units. Some or all of the units may be selected depending onactual requirements to achieve the objectives of the solutions of theembodiments.

In addition, functional units in the embodiments of the presentinvention may be integrated into one processing unit, or each of theunits may exist alone physically, or two or more units may be integratedinto one unit. The integrated unit may be implemented in a form ofhardware, or may be implemented in a form of hardware in addition to asoftware functional unit.

The integrated unit implemented in a form of a software functional unitmay be stored in a non-volatile computer readable storage medium. Thesoftware functional unit is stored in a non-volatile storage medium andincludes several instructions for instructing a computer device (whichmay be a personal computer, a server, a network device, or the like) toperform some of the steps of the methods described in the embodiments ofthe present invention. The foregoing storage medium includes any mediumthat can store program code, for example, a USB flash drive, a removablehard disk, a read-only memory (Read-Only Memory. ROM), a random accessmemory RAM, a magnetic disk, or an optical disc.

Finally, it should be noted that the foregoing embodiments are merelyintended for describing the technical solutions of the presentinvention, but not for limiting the present invention. Although thepresent invention is described in detail with reference to the foregoingembodiments, a person of ordinary skill in the art should understandthat they may still make modifications to the technical solutionsdescribed in the foregoing embodiments or make equivalent replacementsto some technical features thereof, without departing from the scope ofthe technical solutions of the embodiments of the present invention.

1.-19. (canceled)
 20. An audio output method, wherein the audio output method is applied to an electronic device having a proximity sensor, and wherein the audio output method comprises: obtaining proximity data of the proximity sensor when the electronic device is coupled to an audio output device and has an audio signal to output; outputting, using an earpiece of the electronic device, the audio signal when the proximity data meets a preset condition; determining a type of the audio output device; and selecting, based on the type of the audio output device, whether to output the audio signal using the audio output device.
 21. The audio output method of claim 20, wherein the audio output device is an earphone, and wherein selecting whether to output the audio signal using the audio output device comprises outputting, by the audio output device, the audio signal.
 22. The audio output method of claim 20, wherein the audio output device is a loudspeaker device, and wherein selecting whether to output the audio signal using the audio output device comprises skipping outputting, by the audio output device, the audio signal.
 23. The audio output method of claim 20, further comprising outputting, by the electronic device, prompt information indicating that the earpiece of the electronic device outputs the audio signal, and wherein the prompt information is a text prompt or a sound prompt.
 24. The audio output method of claim 20, wherein duration in which the proximity data meets the preset condition is greater than a preset time length.
 25. The audio output method of claim 20, wherein the proximity data meets the preset condition, and wherein outputting the audio signal comprises: setting an audio type of the audio signal to a custom audio type; and outputting, using the earpiece, the audio signal based on a preset correspondence between the custom audio type and the earpiece.
 26. The audio output method of claim 20, wherein the proximity data is a distance between the electronic device and an obstacle, and wherein the preset condition comprises that the distance between the electronic device and the obstacle is less than or equal to a preset distance.
 27. An electronic device, comprising: at least one processor; at least one earpiece coupled to the at least one processor; at least one proximity sensor coupled to the at least one processor; and at least one memory coupled to the at least one processor and configured to store instructions that when executed by the at least one processor, cause the electronic device to: obtain proximity data of the at least one proximity sensor when the electronic device is coupled to an audio output device and has an audio signal to output; output, using the at least one earpiece of the electronic device, the audio signal when the proximity data meets a preset condition; determine a type of the audio output device; and select, based on the type of the audio output device, whether to output the audio signal using the audio output device.
 28. The electronic device of claim 27, wherein the audio output device is an earphone, and wherein the instructions when executed by the at least one processor, further cause the electronic device to output, using the audio output device, the audio signal.
 29. The electronic device of claim 27, wherein the audio output device is a loudspeaker device, and wherein the instructions when executed by the at least one processor, further cause the electronic device to skip outputting, using the audio output device, the audio signal.
 30. The electronic device of claim 27, wherein the instructions when executed by the at least one processor, further cause the electronic device to output prompt information when the at least one earpiece of the electronic device outputs the audio signal, and wherein the prompt information is a text prompt or a sound prompt.
 31. The electronic device of claim 27, wherein duration in which the proximity data meets the preset condition is greater than a preset time length.
 32. The electronic device of claim 27, wherein the proximity data meets the preset condition, and wherein in a manner of outputting the audio signal, the instructions when executed by the at least one processor, further cause the electronic device to: set an audio type of the audio signal to a custom audio type; and output, using the at least one earpiece, the audio signal based on a preset correspondence between the custom audio type and the earpiece.
 33. The electronic device of claim 27, wherein the proximity data is a distance between the electronic device and an obstacle, and wherein the preset condition comprises that the distance between the electronic device and the obstacle is less than or equal to a preset distance.
 34. A non-transitory computer readable medium comprising instructions causing an electronic device to: obtain proximity data of a proximity sensor when the electronic device is coupled to an audio output device and has an audio signal to output; output, using an earpiece of the electronic device, the audio signal when the proximity data meets a preset condition; determine a type of the audio output device; and select, based on the type of the audio output device, whether to output the audio signal using the audio output device.
 35. The non-transitory computer readable medium of claim 34, wherein the audio output device is an earphone, and wherein the instructions further cause the electronic device to output, using the audio output device, the audio signal.
 36. The non-transitory computer readable medium of claim 34, wherein the audio output device is a loudspeaker device, and wherein the instructions further cause the electronic device to skip outputting, using the audio output device, the audio signal.
 37. The non-transitory computer readable medium of claim 34, wherein the instructions further cause the electronic device to output prompt information when the earpiece of the electronic device outputs the audio signal, and wherein the prompt information is a text prompt or a sound prompt.
 38. The non-transitory computer readable medium of claim 34, wherein duration in which the proximity data meets the preset condition is greater than a preset time length.
 39. The non-transitory computer readable medium of claim 34, wherein the proximity data meets the preset condition, and wherein the instructions further cause the electronic device to: set an audio type of the audio signal to a custom audio type; and output, using the earpiece, the audio signal based on a preset correspondence between the custom audio type and the earpiece. 